<?php
	class loaigiaodichdb
	{
		public function Them($MaLoaiGiaoDich = 0, $TenLoaiGiaoDich = "")
		{
			$sql = "INSERT INTO loaigiaodich(MaLoaiGiaoDich, TenLoaiGiaoDich)
					VALUES($MaLoaiGiaoDich, '$TenLoaiGiaoDich')";
			
			$data = new dataservice();
			return $data->ExecuteNonQuery($sql);
		}
		
		public function TonTaiTrongKeKhaiGiaoDich($MaLoaiGiaoDich = 0)
		{
			$sql = "SELECT * FROM kekhaigiaodich WHERE 1";
			if($MaLoaiGiaoDich > 0)
				$sql.= " AND MaLoaiGiaoDich = $MaLoaiGiaoDich";
			$data = new dataservice();
			return $data->ExecuteQuery($sql);
		}
		
		public function CapNhat($MaLoaiGiaoDich = 0, $TenLoaiGiaoDich = "")
		{
			$sql = "UPDATE loaigiaodich 
					SET TenLoaiGiaoDich = '$TenLoaiGiaoDich' 
					WHERE MaLoaiGiaoDich = $MaLoaiGiaoDich";
			
			$data = new dataservice();
			return $data->ExecuteNonQuery($sql);
		}
		
		public function Xoa($MaLoaiGiaoDich = 0)
		{
			$sql = "DELETE FROM loaigiaodich 
					WHERE MaLoaiGiaoDich = $MaLoaiGiaoDich";
			
			$data = new dataservice();
			return $data->ExecuteNonQuery($sql);
		}
		
		public function XoaTatCa()
		{
			$sql = "DELETE FROM loaigiaodich";			
			$data = new dataservice();
			return $data->ExecuteNonQuery($sql);
		}
		
		public function LayDanhSach($MaLoaiGiaoDich = 0, $TenLoaiGiaoDich = "")
		{
			$sql = "SELECT * 
					FROM loaigiaodich 
					WHERE 1";
			
			if($MaLoaiGiaoDich > 0)
				$sql .= " AND MaLoaiGiaoDich = $MaLoaiGiaoDich";
				
			if($TenLoaiGiaoDich != "")
				$sql .= " AND TenLoaiGiaoDich = '$TenLoaiGiaoDich'";
			
			$data = new dataservice();
			return $data->ExecuteQuery($sql);
		}
	}
?>